// var i;
// var $item_Shop_TodayItem_UIBindings = require("./Item_Shop_TodayItem_UIBindings");
// var $resKeeper = require("./ResKeeper");
// var $const_Hall = require("./Const_Hall");
// var $excel = require("./Excel");
// var $hallManager = require("./HallManager");
// var $tipsManager = require("./TipsManager");
// var $playerDataManager = require("./PlayerDataManager");
// var $uIManager = require("./UIManager");
// var $uIConfig_Home = require("./UIConfig_Home");
// var $bundleConfig = require("./BundleConfig");
// var $commonUtils = require("./CommonUtils");
// var $aDManager = require("./ADManager");
// var $eventManager = require("./EventManager");
// var $evenType = require("./EvenType");
// var $redPointControl = require("./RedPointControl");
// var $hallGlobalVariable = require("./HallGlobalVariable");
// var x = cc._decorator;
// var C = x.ccclass;
// var B = x.property;
// var k = x.inspector;
// var P = (function (e) {
//     function t() {
//         var t = (null !== e && e.apply(this, arguments)) || this;
//         t.auto_ui = null;
//         t.childIndex = 0;
//         t.isStart = !0;
//         return t;
//     }
//     __extends(t, e);
//     t.prototype.StartSet = function (e) {
//         var t = this.node.getChildByName("redPoint");
//         if (t) {
//             t.active = 0 == e;
//         }
//         this.childIndex = e;
//         this.auto_ui.node_discountNode.active = !1;
//         var o = $excel.Excel.shopControl(1);
//         this.auto_ui.node_goldbg.active = 0 == e;
//         this.auto_ui.btn_buyBtn.interactable = !0;
//         if (0 == e) {
//             if (this.isStart) {
//                 this.isStart = !1;
//                 this.auto_ui.txt_nameLabel.string = "钻石";
//                 this.auto_ui.txt_countLabel.string = "x" + o.todayDiamondCount;
//             }
//             if (0 == $hallManager.HallMgr.shopData.todayBuyDiamondCount) {
//                 this.auto_ui.txt_priceLabel.string = "免费";
//                 this.auto_ui.node_videoIcon.active = !1;
//             } else {
//                 {
//                     var n = o.getDiamondTime - $hallManager.HallMgr.shopData.todayBuyDiamondCount + 1;
//                     if (n <= 0) {
//                         this.auto_ui.txt_priceLabel.string = "已售罄";
//                         this.auto_ui.node_videoIcon.active = !1;
//                         this.auto_ui.btn_buyBtn.interactable = !1;
//                     } else {
//                         this.auto_ui.txt_priceLabel.string = "免费(" + n + ")";
//                         this.auto_ui.node_videoIcon.active = !0;
//                     }
//                 }
//             }
//         } else {
//             var i = $hallManager.HallMgr.shopData.todayShopArray[e - 1];
//             this.todayShopData = $excel.Excel.todayShop(i.shopId);
//             this.LoadSprite(this.todayShopData.shuiguoId);
//             this.auto_ui.txt_nameLabel.string = this.todayShopData.showName;
//             this.auto_ui.txt_countLabel.string = "x" + this.todayShopData.count;
//             if (1 == i.discount) {
//                 this.auto_ui.node_discountNode.active = !1;
//             } else {
//                 this.auto_ui.node_discountNode.active = !0;
//                 this.auto_ui.txt_discountLabel.string = 10 * i.discount + "折";
//             }
//             if (i.canBuyCount > 0) {
//                 this.auto_ui.node_goldIcon.active = i.richType == $const_Hall.RichType.金币;
//                 this.auto_ui.node_diamondIcon.active = i.richType == $const_Hall.RichType.钻石;
//                 this.auto_ui.txt_priceLabel.string = "" + i.price;
//             } else {
//                 this.auto_ui.node_goldIcon.active = !1;
//                 this.auto_ui.node_diamondIcon.active = !1;
//                 this.auto_ui.txt_priceLabel.string = "已售罄";
//                 this.auto_ui.btn_buyBtn.interactable = !1;
//             }
//         }
//     };
//     t.prototype.LoadSprite = function (e) {
//         return __awaiter(this, void 0, void 0, function () {
//             var t = this;
//             return __generator(this, function () {
//                 this._loadRes(
//                     $bundleConfig.BundleNames.Common,
//                     "res/player/player" + (e - 1e3) + "_1",
//                     cc.SpriteFrame
//                 ).then(function (e) {
//                     t.auto_ui.sp_iconSprite.spriteFrame = e;
//                     $commonUtils.default.LimitSpriteMaxSize(t.auto_ui.sp_iconSprite, $const_Hall.equipIconSize);
//                 });
//                 this._loadRes(
//                     $bundleConfig.BundleNames.Common,
//                     "res/quality/quality_" + $excel.Excel.shuiguo(e).quality,
//                     cc.SpriteFrame
//                 ).then(function (e) {
//                     t.auto_ui.sp_qualitySprite.spriteFrame = e;
//                 });
//                 return [2];
//             });
//         });
//     };
//     t.prototype.onLoad = function () {
//         this.auto_ui.addClickListener(this._clickListener, this);
//     };
//     t.prototype._clickListener = function (e) {
//         switch (e) {
//             case this.auto_ui.btn_buyBtn:
//                 this.BuyThis();
//         }
//     };
//     t.prototype.BuyThis = function () {
//         var e = this;
//         if (0 == this.childIndex) {
//             var t = $excel.Excel.shopControl(1);
//             if (0 == t.gold1Time - $hallManager.HallMgr.shopData.todayBuyDiamondCount + 1) {
//                 return void $tipsManager.TipMgr.showToast("已售罄");
//             }
//             var o = new $const_Hall.GetItemsData();
//             o.ids = [$hallGlobalVariable.default.diamondId];
//             o.counts = [t.todayDiamondCount];
//             o.clickCallBack = function () {
//                 $tipsManager.TipMgr.showToast("购买成功，获得钻石" + t.todayDiamondCount);
//                 e.StartSet(e.childIndex);
//             };
//             if (0 == $hallManager.HallMgr.shopData.todayBuyDiamondCount) {
//                 $playerDataManager.PlayerDataMgr.AddDiamond(t.todayDiamondCount);
//                 $hallManager.HallMgr.shopData.todayBuyDiamondCount++;
//                 $hallManager.HallMgr.SaveShopData();
//                 $eventManager.EventMgr.dispatchEvent(
//                     $evenType.EVENT_TYPE.MainRedPointChange,
//                     $redPointControl.RedPointType.freeDiamond
//                 );
//                 $uIManager.default.open($bundleConfig.BundleNames.Home, $uIConfig_Home.UIView_Home.UI_GetItems, o);
//             } else {
//                 $aDManager.ADMgr.showRewardedVideo("商城视频购买钻石", function () {
//                     $playerDataManager.PlayerDataMgr.AddDiamond(t.todayDiamondCount);
//                     $hallManager.HallMgr.shopData.todayBuyDiamondCount++;
//                     $hallManager.HallMgr.SaveShopData();
//                     $uIManager.default.open($bundleConfig.BundleNames.Home, $uIConfig_Home.UIView_Home.UI_GetItems, o);
//                 });
//             }
//         } else {
//             var n = $hallManager.HallMgr.shopData.todayShopArray[this.childIndex - 1];
//             if (n.canBuyCount <= 0) {
//                 $tipsManager.TipMgr.showToast("已售罄");
//             } else {
//                 {
//                     var i = this;
//                     var a = new $const_Hall.ShopItemInfoData();
//                     a.titleName = this.auto_ui.txt_nameLabel.string;
//                     a.count = this.todayShopData.count;
//                     a.richType = n.richType;
//                     a.price = n.price;
//                     a.infoStr = this.todayShopData.describe;
//                     a.iconSpriteFrame = this.auto_ui.sp_iconSprite.spriteFrame;
//                     a.qualitySpriteFrame = this.auto_ui.sp_qualitySprite.spriteFrame;
//                     a.clickCallBack = function () {
//                         if (n.richType == $const_Hall.RichType.金币) {
//                             if (!$playerDataManager.PlayerDataMgr.SubGold(n.price)) {
//                                 return;
//                             }
//                         } else {
//                             if (!$playerDataManager.PlayerDataMgr.SubDiamond(n.price)) {
//                                 return;
//                             }
//                         }
//                         $playerDataManager.PlayerDataMgr.AddEquipFragments(
//                             i.todayShopData.shuiguoId,
//                             i.todayShopData.count
//                         );
//                         $hallManager.HallMgr.shopData.todayShopArray[i.childIndex - 1].canBuyCount--;
//                         $hallManager.HallMgr.SaveShopData();
//                         var e = new $const_Hall.GetItemsData();
//                         e.ids = [i.todayShopData.shuiguoId];
//                         e.counts = [i.todayShopData.count];
//                         e.clickCallBack = function () {
//                             $tipsManager.TipMgr.showToast(
//                                 "购买成功，获得" + i.todayShopData.showName + "碎片" + i.todayShopData.count
//                             );
//                             i.StartSet(i.childIndex);
//                         };
//                         $uIManager.default.open(
//                             $bundleConfig.BundleNames.Home,
//                             $uIConfig_Home.UIView_Home.UI_GetItems,
//                             e
//                         );
//                     };
//                     $uIManager.default.open(
//                         $bundleConfig.BundleNames.Home,
//                         $uIConfig_Home.UIView_Home.UI_ShopItemInfo,
//                         a
//                     );
//                 }
//             }
//         }
//     };
//     __decorate([B($item_Shop_TodayItem_UIBindings.default)], t.prototype, "auto_ui", void 0);
//     return __decorate([C], t);
// })($resKeeper.default);
// exports.default = P;

// import Item_Shop_TodayItem_UIBindings from "./Item_Shop_TodayItem_UIBindings";
// import ResKeeper from "./ResKeeper";
// import { Excel } from "./Excel";
// import { HallMgrInstance } from "./HallManager";
// import { TipMgrInstance } from "./TipsManager";
// import { PlayerDataMgr } from "./PlayerDataManager";
// import UIManager from "./UIManager";
// import { UIView_Home } from "./UIConfig_Home";
// import { BundleNames } from "./BundleConfig";
// import CommonUtils  from "./CommonUtils";
// import { ADMgr } from "./ADManager";
// import { EventMgrInstance } from "./EventManager";
// import { EVENT_TYPE } from "./EvenType";
// import { RedPointCtrlInstance, RedPointType } from "./RedPointControl";
// import HallGlobalVariable from "./HallGlobalVariable";
// import { RichType, equipIconSize, GetItemsData, ShopItemInfoData } from "./Const_Hall";

// const { ccclass, property, inspector } = cc._decorator;

// /**
//  * 建议类名：ShopItemComponent
//  */
// @ccclass
// class Item_Shop_TodayItem extends ResKeeper {
//     @property(Item_Shop_TodayItem_UIBindings)
//     auto_ui: Item_Shop_TodayItem_UIBindings = null;

//     childIndex: number = 0;
//     isStart: boolean = true;
//     todayShopData: any;

//     /**
//      * 初始化设置
//      * @param index - 子项索引
//      * 建议方法名：initializeSettings
//      */
//     StartSet(index: number): void {
//         const redPointNode = this.node.getChildByName("redPoint");
//         if (redPointNode) {
//             redPointNode.active = index === 0;
//         }
//         this.childIndex = index;
//         this.auto_ui.node_discountNode.active = false;
//         const shopControlData = Excel.shopControl(1);
//         this.auto_ui.node_goldbg.active = index === 0;
//         this.auto_ui.btn_buyBtn.interactable = true;

//         if (index === 0) {
//             if (this.isStart) {
//                 this.isStart = false;
//                 this.auto_ui.txt_nameLabel.string = "钻石";
//                 this.auto_ui.txt_countLabel.string = "x" + shopControlData.todayDiamondCount;
//             }
//             if (HallMgrInstance.shopData.todayBuyDiamondCount === 0) {
//                 this.auto_ui.txt_priceLabel.string = "免费";
//                 this.auto_ui.node_videoIcon.active = false;
//             } else {
//                 const remainingTimes = shopControlData.getDiamondTime - HallMgrInstance.shopData.todayBuyDiamondCount + 1;
//                 if (remainingTimes <= 0) {
//                     this.auto_ui.txt_priceLabel.string = "已售罄";
//                     this.auto_ui.node_videoIcon.active = false;
//                     this.auto_ui.btn_buyBtn.interactable = false;
//                 } else {
//                     this.auto_ui.txt_priceLabel.string = `免费(${remainingTimes})`;
//                     this.auto_ui.node_videoIcon.active = true;
//                 }
//             }
//         } else {
//             const shopItem = HallMgrInstance.shopData.todayShopArray[index - 1];
//             this.todayShopData = Excel.todayShop(shopItem.shopId);
//             this.LoadSprite(this.todayShopData.shuiguoId);
//             this.auto_ui.txt_nameLabel.string = this.todayShopData.showName;
//             this.auto_ui.txt_countLabel.string = "x" + this.todayShopData.count;
//             if (shopItem.discount === 1) {
//                 this.auto_ui.node_discountNode.active = false;
//             } else {
//                 this.auto_ui.node_discountNode.active = true;
//                 this.auto_ui.txt_discountLabel.string = `${10 * shopItem.discount}折`;
//             }
//             if (shopItem.canBuyCount > 0) {
//                 this.auto_ui.node_goldIcon.active = shopItem.richType === RichType.金币;
//                 this.auto_ui.node_diamondIcon.active = shopItem.richType === RichType.钻石;
//                 this.auto_ui.txt_priceLabel.string = `${shopItem.price}`;
//             } else {
//                 this.auto_ui.node_goldIcon.active = false;
//                 this.auto_ui.node_diamondIcon.active = false;
//                 this.auto_ui.txt_priceLabel.string = "已售罄";
//                 this.auto_ui.btn_buyBtn.interactable = false;
//             }
//         }
//     }

//     /**
//      * 加载精灵资源
//      * @param id - 资源ID
//      * 建议方法名：loadSpriteResource
//      */
//     async LoadSprite(id: number): Promise<void> {
//         const spriteFrame = await this._loadRes(
//             BundleNames.Common,
//             `res/player/player${id - 1000}_1`,
//             cc.SpriteFrame
//         );
//         this.auto_ui.sp_iconSprite.spriteFrame = spriteFrame;
//         CommonUtils.LimitSpriteMaxSize(this.auto_ui.sp_iconSprite, equipIconSize);

//         const qualitySpriteFrame = await this._loadRes(
//             BundleNames.Common,
//             `res/quality/quality_${Excel.shuiguo(id).quality}`,
//             cc.SpriteFrame
//         );
//         this.auto_ui.sp_qualitySprite.spriteFrame = qualitySpriteFrame;
//     }

//     /**
//      * 加载时的初始化
//      * 建议方法名：initializeOnLoad
//      */
//     onLoad(): void {
//         this.auto_ui.addClickListener(this._clickListener, this);
//     }

//     /**
//      * 点击事件监听器
//      * @param target - 点击的目标
//      * 建议方法名：handleClickEvent
//      */
//     private _clickListener(target: any): void {
//         switch (target) {
//             case this.auto_ui.btn_buyBtn:
//                 this.BuyThis();
//                 break;
//         }
//     }

//     /**
//      * 购买商品
//      * 建议方法名：purchaseItem
//      */
//     BuyThis(): void {
//         if (this.childIndex === 0) {
//             const shopControlData = Excel.shopControl(1);
//             if (shopControlData.gold1Time - HallMgrInstance.shopData.todayBuyDiamondCount + 1 === 0) {
//                 TipMgrInstance.showToast("已售罄");
//                 return;
//             }
//             const getItemsData = new GetItemsData();
//             getItemsData.ids = [HallGlobalVariable.diamondId];
//             getItemsData.counts = [shopControlData.todayDiamondCount];
//             getItemsData.clickCallBack = () => {
//                 TipMgrInstance.showToast(`购买成功，获得钻石${shopControlData.todayDiamondCount}`);
//                 this.StartSet(this.childIndex);
//             };
//             if (HallMgrInstance.shopData.todayBuyDiamondCount === 0) {
//                 PlayerDataMgr.AddDiamond(shopControlData.todayDiamondCount);
//                 HallMgrInstance.shopData.todayBuyDiamondCount++;
//                 HallMgrInstance.SaveShopData();
//                 EventMgrInstance.dispatchEvent(
//                     EVENT_TYPE.MainRedPointChange,
//                     RedPointType.freeDiamond
//                 );
//                 UIManager.open(BundleNames.Home, UIView_Home.UI_GetItems, getItemsData);
//             } else {
//                 ADMgr.showRewardedVideo("商城视频购买钻石", () => {
//                     PlayerDataMgr.AddDiamond(shopControlData.todayDiamondCount);
//                     HallMgrInstance.shopData.todayBuyDiamondCount++;
//                     HallMgrInstance.SaveShopData();
//                     UIManager.open(BundleNames.Home, UIView_Home.UI_GetItems, getItemsData);
//                 });
//             }
//         } else {
//             const shopItem = HallMgrInstance.shopData.todayShopArray[this.childIndex - 1];
//             if (shopItem.canBuyCount <= 0) {
//                 TipMgrInstance.showToast("已售罄");
//             } else {
//                 const shopItemInfoData = new ShopItemInfoData();
//                 shopItemInfoData.titleName = this.auto_ui.txt_nameLabel.string;
//                 shopItemInfoData.count = this.todayShopData.count;
//                 shopItemInfoData.richType = shopItem.richType;
//                 shopItemInfoData.price = shopItem.price;
//                 shopItemInfoData.infoStr = this.todayShopData.describe;
//                 shopItemInfoData.iconSpriteFrame = this.auto_ui.sp_iconSprite.spriteFrame;
//                 shopItemInfoData.qualitySpriteFrame = this.auto_ui.sp_qualitySprite.spriteFrame;
//                 shopItemInfoData.clickCallBack = () => {
//                     if (shopItem.richType === RichType.金币) {
//                         if (!PlayerDataMgr.SubGold(shopItem.price)) {
//                             return;
//                         }
//                     } else {
//                         if (!PlayerDataMgr.SubDiamond(shopItem.price)) {
//                             return;
//                         }
//                     }
//                     PlayerDataMgr.AddEquipFragments(
//                         this.todayShopData.shuiguoId,
//                         this.todayShopData.count
//                     );
//                     HallMgrInstance.shopData.todayShopArray[this.childIndex - 1].canBuyCount--;
//                     HallMgrInstance.SaveShopData();
//                     const getItemsData = new GetItemsData();
//                     getItemsData.ids = [this.todayShopData.shuiguoId];
//                     getItemsData.counts = [this.todayShopData.count];
//                     getItemsData.clickCallBack = () => {
//                         TipMgrInstance.showToast(
//                             `购买成功，获得${this.todayShopData.showName}碎片${this.todayShopData.count}`
//                         );
//                         this.StartSet(this.childIndex);
//                     };
//                     UIManager.open(BundleNames.Home, UIView_Home.UI_GetItems, getItemsData);
//                 };
//                 UIManager.open(BundleNames.Home, UIView_Home.UI_ShopItemInfo, shopItemInfoData);
//             }
//         }
//     }
// }

// export default Item_Shop_TodayItem;
import Item_Shop_TodayItem_UIBindings from "./Item_Shop_TodayItem_UIBindings";
import ResKeeper from "./ResKeeper";
import { Excel } from "./Excel";
import { HallMgr } from "./HallManager";
import { TipMgr } from "./TipsManager";
import { PlayerDataMgr } from "./PlayerDataManager";
import UIManager from "./UIManager";
import { UIView_Home } from "./UIConfig_Home";
import { BundleNames } from "./BundleConfig";
import CommonUtils  from "./CommonUtils";
import { ADMgr } from "./ADManager";
import { EventMgrInstance } from "./EventManager";
import { EVENT_TYPE } from "./EvenType";
import { RedPointType } from "./RedPointControl";
import FruitDataManager from "./HallGlobalVariable";
import { RichType, equipIconSize, GetItemsData, ShopItemInfoData } from "./Const_Hall";

const { ccclass, property, inspector } = cc._decorator;

/**
 * 类：Item_Shop_TodayItem (建议类名：ShopItemComponent)
 */
@ccclass
class ShopTodayItem extends ResKeeper {
    @property(Item_Shop_TodayItem_UIBindings)
    auto_ui: Item_Shop_TodayItem_UIBindings = null;

    childIndex: number = 0;
    isStart: boolean = true;
    todayShopData: any;

    /**
     * 初始化设置
     * @param index - 子项索引
     */
    initializeSettings(index: number): void {
        const redPointNode = this.node.getChildByName("redPoint");
        if (redPointNode) {
            redPointNode.active = index === 0;
        }
        this.childIndex = index;
        this.auto_ui.node_discountNode.active = false;
        const shopControlData = Excel.shopControl(1);
        this.auto_ui.node_goldbg.active = index === 0;
        this.auto_ui.btn_buyBtn.interactable = true;

        if (index === 0) {
            if (this.isStart) {
                this.isStart = false;
                this.auto_ui.txt_nameLabel.string = "钻石";
                this.auto_ui.txt_countLabel.string = "x" + shopControlData.todayDiamondCount;
            }
            if (HallMgr.shopData.todayBuyDiamondCount === 0) {
                this.auto_ui.txt_priceLabel.string = "免费";
                this.auto_ui.node_videoIcon.active = false;
            } else {
                const remainingTimes = shopControlData.getDiamondTime - HallMgr.shopData.todayBuyDiamondCount + 1;
                if (remainingTimes <= 0) {
                    this.auto_ui.txt_priceLabel.string = "已售罄";
                    this.auto_ui.node_videoIcon.active = false;
                    this.auto_ui.btn_buyBtn.interactable = false;
                } else {
                    this.auto_ui.txt_priceLabel.string = `免费(${remainingTimes})`;
                    this.auto_ui.node_videoIcon.active = true;
                }
            }
        } else {
            const shopItem = HallMgr.shopData.todayShopArray[index - 1];
            this.todayShopData = Excel.todayShop(shopItem.shopId);
            this.loadSprite(this.todayShopData.shuiguoId);
            this.auto_ui.txt_nameLabel.string = this.todayShopData.showName;
            this.auto_ui.txt_countLabel.string = "x" + this.todayShopData.count;
            if (shopItem.discount === 1) {
                this.auto_ui.node_discountNode.active = false;
            } else {
                this.auto_ui.node_discountNode.active = true;
                this.auto_ui.txt_discountLabel.string = `${10 * shopItem.discount}折`;
            }
            if (shopItem.canBuyCount > 0) {
                this.auto_ui.node_goldIcon.active = shopItem.richType === RichType.Gold;
                this.auto_ui.node_diamondIcon.active = shopItem.richType === RichType.Diamond;
                this.auto_ui.txt_priceLabel.string = `${shopItem.price}`;
            } else {
                this.auto_ui.node_goldIcon.active = false;
                this.auto_ui.node_diamondIcon.active = false;
                this.auto_ui.txt_priceLabel.string = "已售罄";
                this.auto_ui.btn_buyBtn.interactable = false;
            }
        }
    }

    /**
     * 加载精灵资源
     * @param id - 资源ID
     */
    async loadSprite(id: number): Promise<void> {
        const spriteFrame = await this._loadRes(
            BundleNames.Common,
            `res/player/player${id - 1000}_1`,
            cc.SpriteFrame
        );
        this.auto_ui.sp_iconSprite.spriteFrame = spriteFrame;
        CommonUtils.limitSpriteSize(this.auto_ui.sp_iconSprite, equipIconSize);

        const qualitySpriteFrame = await this._loadRes(
            BundleNames.Common,
            `res/quality/quality_${Excel.shuiguo(id).quality}`,
            cc.SpriteFrame
        );
        this.auto_ui.sp_qualitySprite.spriteFrame = qualitySpriteFrame;
    }

    /**
     * 加载时的初始化
     */
    onLoad(): void {
        this.auto_ui.addClickListener(this._clickListener, this);
    }

    /**
     * 点击事件监听器
     * @param target - 点击的目标
     */
    private _clickListener(target: any): void {
        switch (target) {
            case this.auto_ui.btn_buyBtn:
                this.buyThis();
                break;
        }
    }

    /**
     * 购买商品
     */
    buyThis(): void {
        if (this.childIndex === 0) {
            const shopControlData = Excel.shopControl(1);
            if (shopControlData.gold1Time - HallMgr.shopData.todayBuyDiamondCount + 1 === 0) {
                TipMgr.showToast("已售罄");
                return;
            }
            const getItemsData = new GetItemsData();
            getItemsData.ids = [FruitDataManager.diamondId];
            getItemsData.counts = [shopControlData.todayDiamondCount];
            getItemsData.clickCallBack = () => {
                TipMgr.showToast(`购买成功，获得钻石${shopControlData.todayDiamondCount}`);
                this.initializeSettings(this.childIndex);
            };
            if (HallMgr.shopData.todayBuyDiamondCount === 0) {
                PlayerDataMgr.addDiamond(shopControlData.todayDiamondCount);
                HallMgr.shopData.todayBuyDiamondCount++;
                HallMgr.saveShopData();
                EventMgrInstance.emitEvent(
                    EVENT_TYPE.MainRedPointChange,
                    RedPointType.freeDiamond
                );
                UIManager.open(BundleNames.Home, UIView_Home.UI_GetItems, getItemsData);
            } else {
                ADMgr.showRewardedVideoAd("商城视频购买钻石", () => {
                    PlayerDataMgr.addDiamond(shopControlData.todayDiamondCount);
                    HallMgr.shopData.todayBuyDiamondCount++;
                    HallMgr.saveShopData();
                    UIManager.open(BundleNames.Home, UIView_Home.UI_GetItems, getItemsData);
                });
            }
        } else {
            const shopItem = HallMgr.shopData.todayShopArray[this.childIndex - 1];
            if (shopItem.canBuyCount <= 0) {
                TipMgr.showToast("已售罄");
            } else {
                const shopItemInfoData = new ShopItemInfoData();
                shopItemInfoData.titleName = this.auto_ui.txt_nameLabel.string;
                shopItemInfoData.count = this.todayShopData.count;
                shopItemInfoData.richType = shopItem.richType;
                shopItemInfoData.price = shopItem.price;
                shopItemInfoData.infoStr = this.todayShopData.describe;
                shopItemInfoData.iconSpriteFrame = this.auto_ui.sp_iconSprite.spriteFrame;
                shopItemInfoData.qualitySpriteFrame = this.auto_ui.sp_qualitySprite.spriteFrame;
                shopItemInfoData.clickCallBack = () => {
                    if (shopItem.richType === RichType.Gold) {
                        if (!PlayerDataMgr.subtractGold(shopItem.price)) {
                            return;
                        }
                    } else {
                        if (!PlayerDataMgr.subtractDiamond(shopItem.price)) {
                            return;
                        }
                    }
                    PlayerDataMgr.addEquipFragments(
                        this.todayShopData.shuiguoId,
                        this.todayShopData.count
                    );
                    HallMgr.shopData.todayShopArray[this.childIndex - 1].canBuyCount--;
                    HallMgr.saveShopData();
                    const getItemsData = new GetItemsData();
                    getItemsData.ids = [this.todayShopData.shuiguoId];
                    getItemsData.counts = [this.todayShopData.count];
                    getItemsData.clickCallBack = () => {
                        TipMgr.showToast(
                            `购买成功，获得${this.todayShopData.showName}碎片${this.todayShopData.count}`
                        );
                        this.initializeSettings(this.childIndex);
                    };
                    UIManager.open(BundleNames.Home, UIView_Home.UI_GetItems, getItemsData);
                };
                UIManager.open(BundleNames.Home, UIView_Home.UI_ShopItemInfo, shopItemInfoData);
            }
        }
    }
}

export default ShopTodayItem;